﻿using System;
using System.Collections.Generic;
using System.Text;

using ECCIT;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DALFactory;
using OgilvyOne.UKNow.Model;

namespace OgilvyOne.UKNow.BLL
{
    public class EventsImageBLL
    {
        public int LanguageID { get; set; }
        public EventsImageBLL(int langID)
        {
            this.LanguageID = langID;
        }

        public ResultInfo Save(EventsImageModel info)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            info.LanguageID = LanguageID;
            return use.Save(info);
        }
        //删除单个图片的数据
        public ResultInfo delImage(int eid)
        {
            IList<int?> list = new List<int?>();
            list.Add(eid);
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            return use.Delete(list);
        }
        //根据图片id 获取该图片信息
        public EventsImageModel selImage(int id)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            return use.GetEventsImageModelByID(id);
        }

        public ResultInfo DeleteImagesByEventsID(int eventsID)
        {
            return EventsImageDALFactory.Create(LanguageID).DeleteByEventsID(null, eventsID);
        }

        /*修改人：穆凤凤
      * 修改时间：2012-01-02
      * 修改内容：
      *      添加方法,修改某个活动图片的发布状态
      *      有mff注释的为本次修改的代码
      */
        //mff
        //修个单个图片的发布状态
        public void modPubOne(int eid)
        {
            List<int?> list = new List<int?>();
            list.Add(eid);

            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);

            EventsImageModel model = use.GetEventsImageModelByID(eid); //查看该图片的当前发布状态
            if (model.State > 0) //该图片的当前为发布状态
            {
                use.UnPublish(list);
                //设置为该图片的state为0 不发布 (传递参数 eid 和 int=0)
            }
            else
            {
                use.Publish(list);
                //设置该图片的state为1 发布     (传递参数 eid 和 int=1)
            }
        }
        //mff
        public IList<EventsImageModel> GetKeyWordEventsImageModels(string keyword)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            return use.GetKeyWordImageModels(keyword);
            
            
        }
        public IList<EventsImageModel> GetAllEventsImageModels(int? eventsID)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            return use.GetAllEventsImageModels(eventsID);
        }

        public EventsImageModel GetAllEventsImageModelsByIds(int? eventsID)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            return use.GetEventsImageModelByID(eventsID);
        }

        public IList<EventsImageModel> GetTop7EventsImageModels(int? eventsID)
        {
            IDALEventsImage use = EventsImageDALFactory.Create(LanguageID);
            IList<EventsImageModel> list = use.GetAllEventsImageModels(eventsID);
            if(list.Count>7){
                return ((List<EventsImageModel>)list).GetRange(0, 7);
            }
            return use.GetAllEventsImageModels(eventsID);
        }

        public IList<EventsImageModel> GetPublishedEventsImageModels(int? eventsID)
        {
            return EventsImageDALFactory.Create(this.LanguageID).GetPublishedEventsImageModels(eventsID);
        }
    }
}
